package com.sk.skplanet.commute.views;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

import com.sk.skplanet.commute.R;
import com.sk.skplanet.commute.controllers.DialogController;
import com.sk.skplanet.commute.controllers.RouteController;
import com.sk.skplanet.commute.daofactory.LocalDaoFactory;
import com.sk.skplanet.commute.vo.BusTblInfo;
import com.sk.skplanet.commute.vo.Data;
import com.sk.skplanet.commute.vo.Point;

public class RouteList extends Activity {

	LinearLayout layout_locationlist;
	Cursor cursor;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.routelist);

		layout_locationlist = (LinearLayout) findViewById(R.id.layout_locationlist);
		Data.routeContext = this;
		
		new LocalDaoFactory(this);
		Cursor result = LocalDaoFactory.getPoints();
		
		if (result.moveToFirst()) {
			while(!result.isAfterLast()) {
				Point point = new Point(
						result.getInt(result.getColumnIndex(BusTblInfo.points._ID)),
						result.getString(result.getColumnIndex(BusTblInfo.points.NAME)),
						0);
				
				layout_locationlist.addView(RouteController.makePoint(this, point));
				
				result.moveToNext();
			}
//			for (int routePosition = 0; routePosition < result.getCount(); routePosition++) {
//				
//				layout_locationlist.addView(RouteController.makeRoute(this, routePosition));
//				// Log.i("루트리스트 접근", Data.memberData.getRoutes().get(routePostion).toString());
//			}
		}

	}
	
	@Override
	protected void onResume() {
		super.onResume();
		
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.routelist, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch(item.getItemId()) {
		case R.id.action_add_route:
			DialogController.createPointDialogAtLocal(RouteList.this).show();
			break;
		default:
			return false;
		}
		
		return true;
	}
}
